﻿using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;
using Nop.Core;
using Nop.Core.Domain.Common;
using Nop.Web.CDN.Models.Common;
using System;

namespace Nop.Web.CDN.Controllers
{
    public partial class CommonController : BasePublicController
    {
        #region Fields

        private readonly CommonSettings _commonSettings;
        private readonly IWebHelper _webHelper;

        #endregion

        #region Constructors

        public CommonController(CommonSettings commonSettings, IWebHelper webHelper)
        {
            this._commonSettings = commonSettings;
            this._webHelper = webHelper;
        }

        #endregion

        #region Utilities
 
        #endregion

        #region Methods


        public ActionResult Index()
        {
            return Content("<div style='width:50%; margin:0 auto; text-align:center;'><h1>Opps 404 Error Occurs ! </h1> <h2>sorry we can't find that page! </h2><h3>Either something went wrong or the page doesn't exist anymore</h3></div>");
        }
        //page not found
        public ActionResult PageNotFound()
        {
            this.Response.StatusCode = 404;
            this.Response.TrySkipIisCustomErrors = true;

            return Content("<div style='width:50%; margin:0 auto; text-align:center;'><h1>Opps 404 Error Occurs ! </h1> <h2>sorry we can't find that page! </h2><h3>Either something went wrong or the page doesn't exist anymore</h3></div>");

        }
        //favicon
        [ChildActionOnly]
        public ActionResult Favicon()
        {
            var model = new FaviconModel()
            {
                Uploaded = System.IO.File.Exists(System.IO.Path.Combine(Request.PhysicalApplicationPath, "favicon.ico")),
                FaviconUrl = _webHelper.GetStoreLocation() + "favicon.ico"
            };

            return PartialView(model);
        }
 
        public ActionResult RobotsTextFile()
        {
            var disallowPaths = new List<string>()
                                    {
                                        "/bin/",
                                        "/content/files/",
                                        "/content/css/",
                                        "/content/assets/",
                                        "/content/files/exportimport/"
                                    };
            var localizableDisallowPaths = new List<string>()
                                               {
                                                    
                                               };


            const string newLine = "\r\n"; //Environment.NewLine
            var sb = new StringBuilder();
            sb.Append("User-agent: *");
            sb.Append(newLine);
            //usual paths
            foreach (var path in disallowPaths)
            {
                sb.AppendFormat("Disallow: {0}", path);
                sb.Append(newLine);
            }
            //localizable paths (without SEO code)
            foreach (var path in localizableDisallowPaths)
            {
                sb.AppendFormat("Disallow: {0}", path);
                sb.Append(newLine);
            }
  

            Response.ContentType = "text/plain";
            Response.Write(sb.ToString());
            return null;
        }
 
        #endregion
    }
}
